﻿using Base.BLL;
using Base.DAL;
using MPSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO.Ports;
using Ay.Framework.WPF;

namespace MPSystem.Views.BasicDataSet
{
    /// <summary>
    /// BasicDataSet_COM.xaml 的交互逻辑
    /// </summary>
    public partial class BasicDataSet_COM : Page
    {
        public BasicDataSet_COM()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_submit_Click(object sender, RoutedEventArgs e)
        {
            SYSTEMCOMB rv = new SYSTEMCOMB();
            rv.COM = comname.Text ;
                rv.BTL = btlcob.SelectedValue.ToString() ;
            rv.JYW = jywcbo.SelectedValue.ToString() ;
                rv.SJW = sjwcbo.SelectedValue.ToString();
            rv.TZW = tzwcbo.SelectedValue.ToString();
            if (ConfigService.SetCOM(rv))
                this.CloseParentWindow();
            else
            {
                AyMessageBox.ShowError("设置错误！！");
            }
        }

        private void btn_cancel_Click(object sender, RoutedEventArgs e)
        {
            this.CloseParentWindow();
        }

        private void GroupBox_Loaded(object sender, RoutedEventArgs e)
        {
         
            if (ConditonsModel.Name == "-1")
            {
                AyMessageBox.ShowError("请选择一个有效数据！！");
                this.CloseParentWindow();
                return;
            }
            AddParameters();
            var rv=  ConfigService.GetCOM(ConditonsModel.Name);//获取串口配置  
            //if (rv.)
            {
                comname.Text = rv.COM;
                btlcob.SelectedValue = rv.BTL;
                jywcbo.SelectedValue = rv.JYW;
                sjwcbo.SelectedValue = rv.SJW;
                tzwcbo.SelectedValue = rv.TZW;
            }


        }
        private void AddParameters()
        {
            //波特率
              object[] BaudRate =  new object[] { "300", "600", "1200", "2400", "4800", "9600", "14400", "19200", "38400"};
            btlcob.ItemsSource = BaudRate;
            //数据直接
            object[] DataBit=new object[] { "5", "6", "7", "8" };
           sjwcbo.ItemsSource = DataBit;
            //停止直接
            object[] StopBit=new object[] { "0.5", "1", "1.5", "2" };
            tzwcbo.ItemsSource = StopBit;
            //奇偶
            object[] ParityBit=new object[] { "NONE", "EVEN", "ODD", "MARK","SPACE" };
           jywcbo.ItemsSource = ParityBit;

        }

    }
}
